package ps.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import ps.client.gui.dpsoverlay.DpsListEntry;





public class DpsParseContent implements PacketContent {
    
    String title;
    String time;
    String damage;
    String dps;
    
    DpsListEntry[] dpsListEntries;
    
    public DpsParseContent() {
    }
    
//    public DpsParseContent(String title, String time, DpsListEntry[] dpsListEntries) {
//        this.title = title;
//        this.time = time;
//        this.dpsListEntries = dpsListEntries;
//    }
    
    @Override
    public void writeContent(OutputStream out) throws IOException {
        // write title
        Packet.writeString(out, title);
        // write time
        Packet.writeString(out, time);
        // write damage
        Packet.writeString(out, damage);
        // write dps
        Packet.writeString(out, dps);
        
        // write count
        out.write(dpsListEntries.length);
        
        for (DpsListEntry entry : dpsListEntries) {
            // write name
            Packet.writeString(out, entry.getName());
            // write dps
            Packet.writeString(out, entry.getDps());
        }
    }
    
    @Override
    public void readContent(InputStream in) throws IOException {
        // read title
        title = Packet.readString(in);
        // read time
        time = Packet.readString(in);
        // read damage
        damage = Packet.readString(in);
        // read dps
        dps = Packet.readString(in);
        
        // read count
        int count = in.read();
        dpsListEntries = new DpsListEntry[count];
        for (int i = 0; i < dpsListEntries.length; i++) {
            dpsListEntries[i] = new DpsListEntry();
            // read name
            dpsListEntries[i].setName(Packet.readString(in));
            // read dps
            dpsListEntries[i].setDps(Packet.readString(in));
        }
    }
    
    @Override
    public String toString() {
        String ret = "[ DpsParse |";
        ret += " title=\"" + title + "\"";
        ret += " time=\"" + time + "\"";
        ret += " damage=\"" + damage + "\"";
        ret += " dps=\"" + dps + "\"";
        for (DpsListEntry entry : dpsListEntries) {
            ret += "\r\n";
            ret += " name=\"" + entry.getName() + "\"";
            ret += " dps=\"" + entry.getDps() + "\"";
        }
        ret += " ]";
        return ret;
    }

    
    public String getTitle() {
        return title;
    }

    
    public void setTitle(String title) {
        this.title = title;
    }

    
    public String getTime() {
        return time;
    }

    
    public void setTime(String time) {
        this.time = time;
    }

    
    public String getDps() {
        return dps;
    }

    
    public void setDps(String dps) {
        this.dps = dps;
    }

    
    public DpsListEntry[] getDpsListEntries() {
        return dpsListEntries;
    }

    
    public void setDpsListEntries(DpsListEntry[] dpsListEntries) {
        this.dpsListEntries = dpsListEntries;
    }

    
    public String getDamage() {
        return damage;
    }

    
    public void setDamage(String damage) {
        this.damage = damage;
    }
    
    
    
}
